home *** CD-ROM | disk | FTP | other *** search
- Path: hilbert.dnai.com!usenet
- From: Victor Bazarov <vbazarov@imsisoft.com>
- Newsgroups: comp.lang.c
- Subject: Re: i = atoi(NULL);
- Date: Sat, 13 Jan 1996 10:05:26 -0800
- Organization: IMSI
- Message-ID: <30F7F466.F43@imsisoft.com>
- References: <DKwCsG.IGD@cs.openu.ac.il> <96009.103802DSEAMA41@portland.caps.maine.edu>
- NNTP-Posting-Host: vbazarov.imsisoft.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b4a (Win16; I)
-
- Starduster wrote:
- >
- > In article <DKwCsG.IGD@cs.openu.ac.il>, shimoco@mail.tlm.openu.ac.il (Shimon
- > Cohen) says:
- > >Hi !
- > >
- > >What ANSI C says about:
- > >i = atoi(NULL);
-
- Actually, nothing specific.
- ------------------------------------------------------------------------------
- 7.10.1.2
- int atoi(const char *nptr);
- "The atoi function converts the initial portion of the string pointed by nptr
- to int representation. Except for the behavior on error, it is equivalent to
- (int)strtol(nptr, (char **)NULL, 10)
-
- 7.10.1.5
- long int strtol(const char *nptr, char **endptr, int base);
- [...]
- "In other than "C" locale, additional implementation-defined subject sequence
- forms may be accepted.
- If the subject is empty or does not have the expected form, no conversion is
- performed; ... If no conversion could be performed, zero is returned."
- ------------------------------------------------------------------------------
- My advice -- check the pointer for being NULL before passing to atoi().
-
- > One question: why does it matter? Why would you want to do such a thing?
- > Just curious.
-
- I think Shimon wanted to use atoi with the argument got from another function,
- which returns NULL in case of empty input, errors, or the like.
-
- > -Darryl
-
- Victor.
-
- --
- Signature.
-